package org.linlinjava.litemall.db.domain;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * litemall税
 *
 * @author yliyun
 * @date 2022/12/02
 */
@Data
@TableName("litemall_tax")
public class LitemallTax {

    public static String TAX_GST = "GST";

    public static String TAX_HST = "HST";

    public static String TAX_PST = "PST";


    /**
     * 被删除
     */
    public static final Boolean IS_DELETED = Deleted.IS_DELETED.value();

    /**
     * 不删除
     */
    public static final Boolean NOT_DELETED = Deleted.NOT_DELETED.value();

    /**
     * id
     */
    @TableId
    private Integer id;

    /**
     * 第一个区域id
     */
    private Integer firstRegionId;

    /**
     * 第二个区域id
     */
    private Integer secondRegionId;

    /**
     * 区域id
     */
    private Integer regionId;

    /**
     * 类型
     */
    private Byte type;

    /**
     * 名字
     */
    private String name;

    /**
     * 代码
     */
    private String code;

    /**
     * 价值
     */
    private BigDecimal value;

    /**
     * 启用
     */
    private Boolean enable;

    /**
     * 添加时间
     */
    private LocalDateTime addTime;

    /**
     * 更新用户id
     */
    private Integer updateUserId;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    /**
     * 删除
     */
    @TableLogic
    private Boolean deleted;

    public enum Deleted {
        NOT_DELETED(new Boolean("0"), "未删除"),
        IS_DELETED(new Boolean("1"), "已删除");

        private final Boolean value;

        private final String name;

        Deleted(Boolean value, String name) {
            this.value = value;
            this.name = name;
        }

        public Boolean getValue() {
            return this.value;
        }

        public Boolean value() {
            return this.value;
        }

        public String getName() {
            return this.name;
        }
    }

    public enum Column {
        id("id", "id", "INTEGER", false),
        firstRegionId("first_region_id", "firstRegionId", "INTEGER", false),
        secondRegionId("second_region_id", "secondRegionId", "INTEGER", false),
        regionId("region_id", "regionId", "INTEGER", false),
        type("type", "type", "TINYINT", true),
        name("name", "name", "VARCHAR", true),
        code("code", "code", "VARCHAR", false),
        value("value", "value", "DECIMAL", true),
        enable("enable", "enable", "BIT", true),
        addTime("add_time", "addTime", "TIMESTAMP", false),
        updateUserId("update_user_id", "updateUserId", "INTEGER", false),
        updateTime("update_time", "updateTime", "TIMESTAMP", false),
        deleted("deleted", "deleted", "BIT", false);

        private static final String BEGINNING_DELIMITER = "`";

        private static final String ENDING_DELIMITER = "`";

        private final String column;

        private final boolean isColumnNameDelimited;

        private final String javaProperty;

        private final String jdbcType;

        public String value() {
            return this.column;
        }

        public String getValue() {
            return this.column;
        }

        public String getJavaProperty() {
            return this.javaProperty;
        }

        public String getJdbcType() {
            return this.jdbcType;
        }

        Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
            this.column = column;
            this.javaProperty = javaProperty;
            this.jdbcType = jdbcType;
            this.isColumnNameDelimited = isColumnNameDelimited;
        }

        public String desc() {
            return this.getEscapedColumnName() + " DESC";
        }

        public String asc() {
            return this.getEscapedColumnName() + " ASC";
        }

        public static Column[] excludes(Column ... excludes) {
            ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
            if (excludes != null && excludes.length > 0) {
                columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
            }
            return columns.toArray(new Column[]{});
        }

        public String getEscapedColumnName() {
            if (this.isColumnNameDelimited) {
                return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
            } else {
                return this.column;
            }
        }

        public String getAliasedEscapedColumnName() {
            return this.getEscapedColumnName();
        }
    }
}
